package com.examples.graphics;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

public class GraphicsExample {
	public static void main(String[] args) {
	
		final Display display = Display.getDefault();
		final Shell shell = new Shell(display); 
		shell.addPaintListener(new PaintListener(){ 
		        public void paintControl(PaintEvent e){ 
		            Rectangle clientArea = shell.getClientArea(); 
//		       /  e.gc.drawLine(0,0,clientArea.width,clientArea.height);
		         e.gc.setClipping(20, 20, clientArea.width-40, clientArea.height-40);
		         e.gc.setBackground(display.getSystemColor(SWT.COLOR_RED));
		         e.gc.fillPolygon(new int[] {0,0,clientArea.width,0,clientArea.width,clientArea.height/2}); 
		        } 
		    }); 
		shell.setSize(150,150);
		shell.open();
		while(!shell.isDisposed()){
			if(!display.readAndDispatch()){
				display.sleep();
			}
		}
		//display.dispose(); //Commented only for SWTShowcase application.
	}

}
